package main

//使用验证器验证参数

import (
	"fmt"
	"github.com/go-playground/validator/v10"
)

var val = validator.New()

type RegestRequest struct {
	UserName   string `validate:"gt=6"`
	Passwd     string `validate:"min=6,max=12"`
	PassRepeat string `validate:"eqfield=Passwd"`
	Email      string `validate:"email"`
}

type InnerRequest struct {
	Passwd string `validate:"min=6,max=12"`
	Email  string `validate:"email"`
}

type OutterRequest struct {
	UserName   string `validate:"gt=6"`
	PassRepeat string `validate:"eqcsfield=Nest.Passwd"`
	Nest       InnerRequest
}

func main() {
	inreq := InnerRequest{
		Passwd: "qwde32er32r23dc324234",
		Email:  "ewqrewr@fdd2d",
	}

	outreq := OutterRequest{
		UserName:   "weasd",
		PassRepeat: "wwee333d",
		Nest:       inreq,
	}

	err := val.Struct(outreq)
	if err != nil {
		fmt.Println(err)
	}
}
